﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>ELR</title>
    <link rel="stylesheet" type="text/css" href="styles/enviarPassword.css" />
    <script type="text/javascript" src="Scripts/jquery/jquery-1.7.2.js"></script>
    <script type="text/javascript" src="Scripts/closure/closure-library/closure/goog/base.js"></script>
</head>
<body>
<div style="padding: 100px 0 0 250px;">
    <div id="recuperarPasswordContent">
        <H2>Recuperar Password</H2>
        Ingrese su cuenta de correo electrónico para enviarle un nuevo password
        <br />
        <br/>
        <div id="login-box-name" style="margin-top:20px;">Email:</div>
            <div id="login-box-field" style="margin-top:20px;">
                <input id="mailEnviarContraseña" name="q" class="form-login" title="Username" value="" size="30" maxlength="2048" />
            </div>
        <div id="enviarNuevoPassword"><p>Enviar</p></div>
        <br />
        <br />
        <br />
        <div class="validateUser"><label class="validarUsuario"></label></div>
    </div>
</div>
<script type="text/javascript">
    $("#enviarNuevoPassword").click(function(){
        var val = $("#mailEnviarContraseña").val();
        if (val == "") {
            $('.validateUser').css({ color: "#4D29DB" });
            $('.validateUser').css({ background: "#ebebeb" });
            $('.validarUsuario').html('Ingrese un correo');
            return false;
        }
        else if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(val)) {
            $('.validateUser').css({ color: "#4D29DB" });
            $('.validateUser').css({ background: "#ebebeb" });
            $('.validarUsuario').html('Ingrese un correo valido');
            return false;
        } else{
            console.log(val);
            $.ajax({
                type: "POST"
                ,url: "Services/User.svc/UpdateFlagRecoverUserPassword"
                ,data: '{"USER_MAIL":"'+ val +'"}'
                ,contentType: "application/json; charset=utf-8"
                ,dataType: "json"
                ,success: function (data) {
                    console.log(data.UpdateFlagRecoverUserPasswordResult);
                    var test = "";
                    test = data.UpdateFlagRecoverUserPasswordResult;
                    if (test == 1) {
                        $('.validateUser').css({ color: "#4D29DB" });
                        $('.validateUser').css({ background: "#ebebeb" });
                        $('.validarUsuario').html('Un nuevo password sera enviado a su correo');
                    } else {
                        $('.validateUser').css({ color: "#4D29DB" });
                        $('.validateUser').css({ background: "#ebebeb" });
                        $('.validarUsuario').html('No existe un usuario con esta cuenta de correo');
                    }
                }
                ,error: function (result) {
                    alert('Error al enviar password ' + result.status + ' ' + result.statusText);
                }
            });
        }
    });
</script>
</body>
</html>
